require("SOD/tools/dialogs/dialog.rb")
require("SOD/ProjectManager.rb")

module SOD
  
  class ProjectInfoDialog < SOD_Dialog # see OS Dialog
    
    def initialize(title = "Default", scrollbars = true, w = 660, h = 580, l = 150, t = 150)
      super
      set_file("projectInfo.html")
      add_callbacks
    end
    
    def add_callbacks
      super
      @webDialog.add_action_callback("showVolumes") do |d, p|
	Plugin.drawModelInterface.drawVolumes
      end
    end
    
    def onLoad
      update
    end
    
    def update
      
      floorDesignArray = Plugin.designRules.floorDesign
      flexibilityArray = Plugin.designRules.flexibility
      storeyArray = Plugin.designRules.storeyList
      
      @projectName = "Project1"#Plugin.projectManager.activeProjectName
      @roomsize = Plugin.model.projectInfo.roomsize
      @flexibility = Plugin.model.projectInfo.flexibility
      @storeys = Plugin.model.projectInfo.numberOfStoreys.to_s
      
      if @projectName.nil?
        @projectName = "No Project Active!"
      else
        set_select_options("ROOMSIZE", floorDesignArray)
        set_select_options("FLEXIBILITY", flexibilityArray)
        set_select_options("STOREYS", storeyArray)
        
        set_element_value("ROOMSIZE", @roomsize)
        set_element_value("FLEXIBILITY", @flexibility)
        set_element_value("STOREYS", @storeys)
      end
      
      set_element_value("NAME", @projectName)
      
      #@hash['ROOMSIZE'] = Plugin.model.projectInfo.roomsize
      #@hash['FLEXIBILITY'] = Plugin.model.projectInfo.felxibility
      #@hash['STOREYS'] = Plugin.model.projectInfo.numberOfStoreys
      #
      #@hash.keys.each { |key| set_element_value( key , @hash[key]) }
    end
    
    def on_change_element(d, p)
      # problem here:  assumes value does not have any commas in it, need to just split off first one
      args = p.split(",")
      key = args[0]
      value = args[1]
      
      case(key)
      when "ROOMSIZE"
        Plugin.model.projectInfo.roomsize = value
      when "FLEXIBILITY"
        Plugin.model.projectInfo.flexibility = value
      when "STOREYS"
        Plugin.model.projectInfo.numberOfStoreys = value.to_i
      else
        puts "ProjectInfo: No matching Value returned!" if $debug
      end
    end
    
  end
  
end
